<title>应用管理</title>
<#include "../common/common.html"/>

<div class="row">
	<div class="col-xs-12">
		<div class="row">
			<div class="col-xs-12">
				<div class="widget-box">
					<div class="widget-header widget-header-small">
						<h5 class="widget-title lighter">搜索栏</h5>
					</div>

					<div class="widget-body">
						<div class="widget-main">
							<form id="_form" class="form-inline">
								<label>
									<label class="control-label" for="form-field-1"> 名称： </label>
									<input name="name" type="text" class="form-data input-medium search-data">
								</label>
								<!-- 
								<button id="_search" type="button" class="btn btn-info btn-sm">
									<i class="ace-icon fa fa-search bigger-110"></i>搜索
								</button>
								 -->
							</form>
						</div>
					</div>
				</div>

				<div>
					<div class="dataTables_wrapper form-inline no-footer">
						<table id="_table" class="table table-striped table-bordered table-hover dataTable no-footer">
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>

	<a id="my-modal-a" href="#my-modal" role="button" class="bigger-125 bg-primary white" style="display: none;" data-toggle="modal"></a>

	<div id="my-modal" class="modal fade" tabindex="-1">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
					<h3 class="smaller lighter blue no-margin">查看应用密钥信息</h3>
				</div>

				<div class="modal-body">
					<form id="_editForm" class="form-horizontal" role="form"
						  validate="true">

						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right"><span class="form-star">*</span>ClientId</label>

							<div class="col-sm-9">
								<label id="_clientId" class="control-label"></label>
							</div>
						</div>

						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right"><span class="form-star">*</span>ClientSecret</label>

							<div class="col-sm-9">
								<label id="_clientSecret" class="control-label"></label>
							</div>
						</div>
					</form>
				</div>

				<div class="modal-footer">
					<button id="_cancel" class="btn btn-sm btn-danger pull-right" data-dismiss="modal" type="reset" >
						<i class="ace-icon fa fa-times"></i>
						关闭
					</button>
				</div>
			</div><!-- /.modal-content -->
		</div><!-- /.modal-dialog -->
	</div>
</div>

<script type="text/javascript">
	$('.page-content-area').ace_ajax('loadScripts', scripts, function() {
		jQuery(function($) {
			// 列表
			var $table = $("#_table").table({
    			url : "${request.contextPath}/admin/app/list",
    			formId : "_form",
				tools : [
					{text : '新增', clazz : 'btn-info', icon : 'fa fa-plus-circle blue', permission : '/admin/app/edit', handler : function(){
						$.aceRedirect("${request.contextPath}/admin/app/edit");
					}},
					{text : '禁用', clazz : 'btn-warning', icon : 'fa fa-lock orange', permission : '/admin/app/enable', handler : function(){
						$table.ajaxEnable({url : "${request.contextPath}/admin/app/enable"}, false);
					}},
					{text : '启用', clazz : 'btn-success', icon : 'fa fa-unlock green', permission : '/admin/app/enable', handler : function(){
						$table.ajaxEnable({url : "${request.contextPath}/admin/app/enable"}, true);
					}},
					{text : '删除', clazz : 'btn-danger', icon : 'fa fa-trash-o red', permission : '/admin/app/delete', handler : function(){
						$table.ajaxDelete({
							confirm : "删除应用会关联删除对应的权限，确认要删除?", 
							url : "${request.contextPath}/admin/app/delete"
						});
					}},
					{text : '查看应用密钥信息', clazz : 'blue', icon : 'fa fa-eye', permission : '/admin/app/credentials', handler : function(){
						if($table.validateSelected(true)){
							$("#_editForm")[0].reset();
							$.getJSON("${request.contextPath}/admin/app/credentials?id=" + $table.getSelectedItemKeys("id"), function(d) {
								$("#_clientId").html(d.data.clientId);
								$("#_clientSecret").html(d.data.clientSecret);
								$("#my-modal-a").click();
							});
						}
					}}
				],
				columns : [
			        {field:'id', hide : true},
			        {field:'isEnable', hide : true},
			        {field:'name', title:'名称', align:'left'},
			        {field:'code', title:'编码', align:'left', mobileHide : true},
			        {field:'sort', title:'排序', mobileHide : true},
			        {field:'isEnableStr', title:'是否启用', replace : function (d){
				        if(d.isEnable)
				        	return "<span class='label label-sm label-success'>是</span>";
			        	else
			        		return "<span class='label label-sm label-warning'>否</span>";
			        }},
			        {field:'createTime', title:'创建时间', mobileHide : true}
				],
				operate : [
					{text : '修改', clazz : 'blue', icon : 'fa fa-pencil', permission : '/admin/app/edit', handler : function(d, i){
						$.aceRedirect("${request.contextPath}/admin/app/edit?id=" + d.id);
					}},
					{text : '禁用', clazz : 'orange', icon : 'fa fa-lock', permission : '/admin/app/enable', 
						handler : function(){
							$table.ajaxEnable({url : "${request.contextPath}/admin/app/enable"}, false);
						},
						show : function(d){
							return d.isEnable;
						}
					},
					{text : '启用', clazz : 'green', icon : 'fa fa-unlock', permission : '/admin/app/enable', 
						handler : function(){
							$table.ajaxEnable({url : "${request.contextPath}/admin/app/enable"}, true);
						},
						show : function(d){
							return !d.isEnable;
						}
					},
					{text : '删除', clazz : 'red', icon : 'fa fa-trash-o', permission : '/admin/app/delete', handler : function(d, i){
						$table.ajaxDelete({
							confirm : "删除应用会关联删除对应的权限，确认要删除?", 
							url : "${request.contextPath}/admin/app/delete"
						});
					}},
					{text : '查看应用密钥信息', clazz : 'blue', icon : 'fa fa-eye', permission : '/admin/app/credentials', handler : function(d, i){
						$("#_editForm")[0].reset();
						$.getJSON("${request.contextPath}/admin/app/credentials?id=" + d.id, function(d) {
							$("#_clientId").html(d.data.clientId);
							$("#_clientSecret").html(d.data.clientSecret);
							$("#my-modal-a").click();
						});
					}}
				],
				after : function(){
					// 权限处理
					$.permission();
				}
			});
			
			// 搜索
			$(".search-data").keyup(function () { 
				$table.search();
			});
		});
	});
</script>
